package com.miao.elm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.miao.elm.dao.DeliveryaddressDao;
import com.miao.elm.entity.DeliveryaddressEntity;
import com.miao.elm.service.DeliveryaddressService;
import com.miao.elm.to.DeliveryAddressTo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;


@Service("deliveryaddressService")
public class DeliveryaddressServiceImpl extends ServiceImpl<DeliveryaddressDao, DeliveryaddressEntity> implements DeliveryaddressService {

    @Override
    public List<DeliveryaddressEntity> listDeliveryAddressByUserId(String userId) {
        return this.baseMapper.selectList(new QueryWrapper<DeliveryaddressEntity>().eq("user_id", userId));
    }

    @Override
    public DeliveryaddressEntity getDeliveryAddressById(Integer daId) {
        return this.baseMapper.selectOne(new QueryWrapper<DeliveryaddressEntity>().eq("da_id", daId));
    }

    @Override
    public int saveDeliveryAddress(DeliveryAddressTo deliveryAddressTo) {
        DeliveryaddressEntity deliveryaddressEntity = new DeliveryaddressEntity();
        BeanUtils.copyProperties(deliveryAddressTo, deliveryaddressEntity);
        return this.baseMapper.insert(deliveryaddressEntity);
    }

    @Override
    public int updateDeliveryAddress(DeliveryAddressTo deliveryAddressTo) {
        DeliveryaddressEntity deliveryaddressEntity = new DeliveryaddressEntity();
        BeanUtils.copyProperties(deliveryAddressTo, deliveryaddressEntity);
        return this.baseMapper.updateById(deliveryaddressEntity);
    }

    @Override
    public int removeDeliveryAddress(Integer daId) {
        return this.baseMapper.deleteById(daId);
    }
}